package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.CmsMemberReport;
import com.macro.mall.model.UmsAdmin;
import com.macro.mall.model.UmsMember;
import com.macro.mall.model.UmsMemberStatisticsInfo;
import com.macro.mall.service.CmsMemberReportService;
import com.macro.mall.service.UmsMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "UmsMemberController", description = "会员管理")
@RequestMapping("/member")
public class UmsMemberContorller {
    @Autowired
    private UmsMemberService umsMemberService;
    @Autowired
    private CmsMemberReportService cmsMemberReportService;
    @ApiOperation("根据用户名或姓名分页获取会员列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<UmsMember>> list(@RequestParam(value = "keyword", required = false) String keyword,
                                                    @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                    @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        List<UmsMember> memberList = umsMemberService.list(keyword, pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(memberList));
    }
    @ApiOperation("删除指定会员信息")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    public CommonResult delete(@PathVariable Long id) {
        int count = umsMemberService.delete(id);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }
    @ApiOperation("修改会员帐号状态")
    @RequestMapping(value = "/updateStatus/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult updateStatus(@PathVariable Long id,@RequestParam(value = "status") Integer status) {
        UmsMember umsMember = new UmsMember();
        umsMember.setStatus(status);
        umsMember.setId(id);
        int count = umsMemberService.update(umsMember);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }
    @ApiOperation("修改会员帐号状态")
    @RequestMapping(value = "/getById/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<UmsMember> getById(@PathVariable Long id) {
        return CommonResult.success(umsMemberService.getById(id));
    }
    @ApiOperation("根据会员ID统计会员信息")
    @RequestMapping(value = "/statistics/getById/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<UmsMemberStatisticsInfo> statisticsGetById(@PathVariable Long id) {
        return CommonResult.success(umsMemberService.statisticsGetById(id));
    }
}
